import { createRouter, createWebHistory } from 'vue-router'
import AuthView from "../views/auth/AuthView.vue";
import MainView from "../views/main/MainView.vue";
import IndexView from "../views/main/views/index-view/IndexView.vue";
import ArtistView from "@/views/main/views/artist-view/ArtistView.vue";
import ConcertView from "@/views/main/views/concert-view/ConcertView.vue";
import FlowView from "@/views/main/views/flow-view/FlowView.vue";
import VideoView from "@/views/main/views/video-view/VideoView.vue";
import OrderView from "@/views/main/views/order-view/OrderView.vue";
import UserView from "@/views/main/views/user-view/UserView.vue";
import CityView from "@/views/main/views/city-view/CityView.vue";
import VenueView from "@/views/main/views/venue-view/VenueView.vue";

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/auth',
            name: 'auth',
            component: AuthView,
            meta: {
                title: '认证页面',
                requiresAuth: false // 是否需要登录
            }
        },
        {
            path: '/',
            name: 'main',
            component: MainView,
            meta: {
                title: '主页面',
                requiresAuth: true // 是否需要登录
            },
            children: [
                {
                    path: '/index',
                    name: 'index',
                    component: IndexView,
                    meta: {
                        title: '首页',
                        requiresAuth: true // 是否需要登录
                    }
                },
                {
                    path: '/artist',
                    name: 'artist',
                    component: ArtistView,
                    meta: {
                        title: '艺人管理',
                        requiresAuth: true // 是否需要登录
                    }
                },
                {
                    path: '/concert',
                    name: 'concert',
                    component: ConcertView,
                    meta: {
                        title: '演唱会管理',
                        requiresAuth: true // 是否需要登录
                    }
                },
                {
                    path: '/flow',
                    name: 'flow',
                    component: FlowView,
                    meta: {
                        title: '流量管理',
                        requiresAuth: true // 是否需要登录
                    }
                },
                {
                    path: '/video',
                    name: 'video',
                    component: VideoView,
                    meta: {
                        title: '视频管理',
                        requiresAuth: true // 是否需要登录
                    }
                },
                {
                    path: '/order',
                    name: 'order',
                    component: OrderView,
                    meta: {
                        title: '订单管理',
                        requiresAuth: true // 是否需要登录
                    }
                },
                {
                    path: '/user',
                    name: 'user',
                    component: UserView,
                    meta: {
                        title: '用户管理',
                        requiresAuth: true // 是否需要登录
                    }
                },
                {
                    path: '/city',
                    name: 'city',
                    component: CityView,
                    meta: {
                        title: '城市管理',
                        requiresAuth: true // 是否需要登录
                    }
                },
                {
                    path: '/venue',
                    name: 'venue',
                    component: VenueView,
                    meta: {
                        title: '场地管理',
                        requiresAuth: true // 是否需要登录
                    }
                },
            ]
        },

    ],
})

// 全局前置守卫
// router.beforeEach((to, from, next) => {
//
//     console.log('全局前置守卫', to, from)
//     // // 设置页面标题
//     // document.title = to.meta.title ? `${to.meta.title} - 我的应用` : '我的应用'
//     //
//     // // 检查是否需要认证
//     // const isAuthenticated = checkAuth() // 假设有一个检查登录状态的方法
//     //
//     // if (to.meta.requiresAuth && !isAuthenticated) {
//     //     next({ name: 'login', query: { redirect: to.fullPath } })
//     // } else if (to.meta.guestOnly && isAuthenticated) {
//     //     next({ name: 'home' }) // 已登录用户访问登录页则跳转首页
//     // } else {
//     //     next()
//     // }
// })

export default router
